/*
 * @file gkt_window_timer.h
 */

#ifndef GKT_WINDOW_TIMER_H
#define GKT_WINDOW_TIMER_H

#include "gkt_types.h"

#ifdef __cplusplus
extern "C" {
#endif

/* WINDOW TIMER EVENT DATA INDEX */
#define GKT_WINDOW_TIMER_EVTDATA_PRIVATE_DATA	0

typedef uint16_t	gkt_window_timer_t;

/* group */
enum {
	GKT_WINDOW_TIMER_GROUP_CUSTOM = 0,
	GKT_WINDOW_TIMER_GROUP_WIDGET,
	GKT_WINDOW_TIMER_GROUP_MANAGE,
	GKT_WINDOW_TIMER_GROUP_MAX
};

#define GKT_WINDOW_TIMER_GROUP_SHIFT	12
#define GKT_WINDOW_TIMER_GROUP_MASK	0xF000
#define GKT_WINDOW_TIMER_GROUP(timer_id)	\
	((timer_id) & GKT_WINDOW_TIMER_GROUP_MASK)

#define GKT_WINDOW_TIMER_CUSTOM	\
	(GKT_WINDOW_TIMER_GROUP_CUSTOM << GKT_WINDOW_TIMER_GROUP_SHIFT)
#define GKT_WINDOW_TIMER_WIDGET	\
	(GKT_WINDOW_TIMER_GROUP_WIDGET << GKT_WINDOW_TIMER_GROUP_SHIFT)
#define GKT_WINDOW_TIMER_MANAGE	\
	(GKT_WINDOW_TIMER_GROUP_MANAGE << GKT_WINDOW_TIMER_GROUP_SHIFT)

/* sub group */
#define GKT_WINDOW_TIMER_SUB_GROUP_SHIFT	8
#define GKT_WINDOW_TIMER_SUB_GROUP_MASK	0x0F00

/* sub group of manage timer */
enum {
	GKT_WINDOW_TIMER_MANAGE_TIMEOUT = 0,
	GKT_WINDOW_TIMER_MANAGE_SYSTEM,
	GKT_WINDOW_TIMER_MANAGE_VOICE,
	GKT_WINDOW_TIMER_MANAGE_MAX
};
#define GKT_WINDOW_TIMER_MANAGE_TYPE_MASK	0x00FF

#define GKT_WINDOW_TIMER_MANAGE_TYPE_ID(_SUB_GROUP, TYPE)	\
	(GKT_WINDOW_TIMER_MANAGE \
		| (GKT_WINDOW_TIMER_MANAGE_##_SUB_GROUP << GKT_WINDOW_TIMER_SUB_GROUP_SHIFT)	\
		| ((TYPE) & GKT_WINDOW_TIMER_MANAGE_TYPE_MASK))

/* flags */
#define GKT_WINDOW_TIMER_F_PERIODIC	(1U << 0)
#define GKT_WINDOW_TIMER_F_DETACHED	(1U << 1)

typedef void (*gkt_window_timer_manage_handler)(uint32_t type, 
					uint32_t private_data);
void gkt_window_timer_register_manage_handler(uint32_t timer_id,
			gkt_window_timer_manage_handler handler);

int gkt_window_timer_set(gkt_window_timer_t timer_id, 
				uint32_t interval, uint32_t flgas, 
				uint32_t private_data);

int gkt_window_timer_clear(gkt_window_timer_t timer_id);

void gkt_window_timer_clear_all(gkt_window_id_t window_id);

int gkt_window_timer_init(void);

#ifdef __cplusplus
}
#endif

#endif	/* GKT_WINDOW_TIMER_H */

